<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="课表id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courseScheduleId">
              <a-input v-model="model.courseScheduleId" placeholder="请输入课表id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="目标对象id(班级id(默认)，场地id，老师id，科目id,学生id)，表示该课表应用对象" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="targetObjId">
              <a-input v-model="model.targetObjId" placeholder="请输入目标对象id(班级id(默认)，场地id，老师id，科目id,学生id)，表示该课表应用对象"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联对象类型英文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relObjNameEn">
              <a-input v-model="model.relObjNameEn" placeholder="请输入关联对象类型英文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联对象类型中文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relObjNameCn">
              <a-input v-model="model.relObjNameCn" placeholder="请输入关联对象类型中文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联对象类型(1:班级;2:教室,3.老师;4.科目5学生)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relObjTtype">
              <a-input-number v-model="model.relObjTtype" placeholder="请输入关联对象类型(1:班级;2:教室,3.老师;4.科目5学生)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="星期一：对象id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomMonday">
              <a-input v-model="model.courScheAtomMonday" placeholder="请输入星期一：对象id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="星期二：对象id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomTuesday">
              <a-input v-model="model.courScheAtomTuesday" placeholder="请输入星期二：对象id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="星期三：对象id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomWednesday">
              <a-input v-model="model.courScheAtomWednesday" placeholder="请输入星期三：对象id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="星期四：对象id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomThursday">
              <a-input v-model="model.courScheAtomThursday" placeholder="请输入星期四：对象id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="星期五：对象id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomFriday">
              <a-input v-model="model.courScheAtomFriday" placeholder="请输入星期五：对象id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="星期六：对象id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomSaturday">
              <a-input v-model="model.courScheAtomSaturday" placeholder="请输入星期六：对象id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="星期日：对象id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomSunday">
              <a-input v-model="model.courScheAtomSunday" placeholder="请输入星期日：对象id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="节次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomSection">
              <a-input-number v-model="model.courScheAtomSection" placeholder="请输入节次" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomStartTime">
              <a-input v-model="model.courScheAtomStartTime" placeholder="请输入开始时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomEndTime">
              <a-input v-model="model.courScheAtomEndTime" placeholder="请输入结束时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单双周标识(1单周（默认），2双周 3三周 4四周)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courScheAtomIzSingle">
              <a-input-number v-model="model.courScheAtomIzSingle" placeholder="请输入单双周标识(1单周（默认），2双周 3三周 4四周)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否启用（0否停用，1是启用）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">
              <a-input-number v-model="model.izOpen" placeholder="请输入是否启用（0否停用，1是启用）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CouCourseScheduleAtomForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           relObjNameEn: [
              { required: true, message: '请输入关联对象类型英文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）!'},
           ],
           relObjNameCn: [
              { required: true, message: '请输入关联对象类型中文名称（班级cou_class、教室fac_classroom、老师tea_teacher、科目cou_subject、学生stu_student）!'},
           ],
           relObjTtype: [
              { required: true, message: '请输入关联对象类型(1:班级;2:教室,3.老师;4.科目5学生)!'},
           ],
        },
        url: {
          add: "/coursecheduleatom/couCourseScheduleAtom/add",
          edit: "/coursecheduleatom/couCourseScheduleAtom/edit",
          queryById: "/coursecheduleatom/couCourseScheduleAtom/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>